package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Arrays;
import org.rsbot.bot.Bot;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.Settings;

public class DrawSettings
  implements PaintListener
{
  private static final Font monoFont = Font.decode("Monospaced");
  private static final int TIMEOUT = 5000;
  private int[] lastSettings = new int[0];
  private long[] settingsAge = new long[0];
  private Settings settings;

  public DrawSettings(Bot paramBot)
  {
    this.settings = paramBot.getMethodContext().settings;
  }

  public void onRepaint(Graphics paramGraphics) {
    int[] arrayOfInt = this.settings.getSettingArray();
    if (arrayOfInt != null) {
      Font localFont = paramGraphics.getFont();
      paramGraphics.setFont(monoFont);
      if (arrayOfInt.length > this.lastSettings.length) {
        this.lastSettings = Arrays.copyOf(this.lastSettings, arrayOfInt.length);
        this.settingsAge = Arrays.copyOf(this.settingsAge, arrayOfInt.length);
      }
      int i = 0;
      long l1 = System.currentTimeMillis();
      long l2 = l1 - 5000L;
      for (int j = 0; j < arrayOfInt.length; j++) {
        if (this.settingsAge[j] == 0L) {
          this.settingsAge[j] = (arrayOfInt[j] != 0 ? l2 : l1);
        }
        if (this.lastSettings[j] != arrayOfInt[j]) {
          this.settingsAge[j] = l1;
          this.lastSettings[j] = arrayOfInt[j];
        }
        int k = this.settingsAge[j] > l2 ? 1 : 0;
        int m = arrayOfInt[j] != 0 ? 1 : 0;
        if ((m != 0) || (k != 0)) {
          int n = 10 + 140 * (i % 4);
          int i1 = 70 + 12 * (i / 4);
          String str = String.format("%4d: %d", new Object[] { Integer.valueOf(j), Integer.valueOf(arrayOfInt[j]) });
          paramGraphics.setColor(Color.black);
          paramGraphics.drawString(str, n, i1 + 1);
          paramGraphics.setColor(k != 0 ? Color.red : Color.green);
          paramGraphics.drawString(str, n, i1);
          i++;
        }
      }
      paramGraphics.setFont(localFont);
    }
  }
}